package com.pricetag.googleproductsearch;

import java.io.Serializable;

public class GoogleShopPriceSearchResult implements Comparable<GoogleShopPriceSearchResult>, Serializable{

	private static final long serialVersionUID = 3911844958685853721L;
	private String title;
	private String link;
	private String image;
	private String availability;
	private String price;
	private double priceValue = 0.0;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public String getAvailability() {
		if (availability == null) {
			return null;
		}
		if (availability.equalsIgnoreCase("inStock")) {
			return "In Stock";
		} else {
			return "Out of Stock";
		}
	}

	public void setAvailability(String availability) {
		this.availability = availability;
	}

	public String getPrice() {
		return price;
	}

	public void setPrice(String price) {
		this.priceValue = 0.0;
		try {
			this.priceValue = Double.parseDouble(price);
		} catch (Exception e) {
			e.printStackTrace();
			this.priceValue = 0.0;
		}
		this.price = String.format("%.2f", priceValue);
	}
	
	@Override
	public int compareTo(GoogleShopPriceSearchResult another) {
		if (this.priceValue > another.priceValue) {
			return 1;
		} else if (this.priceValue < another.priceValue) {
			return -1;
		} else {
			return 0;
		}
	}

}
